/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ihmprojet.core.historique;

import ihmprojet.core.model.Arrete;
import ihmprojet.core.model.DelegateTreeOperators;
import ihmprojet.core.model.Sommet;
import ihmprojet.core.model.Sommet.Type;

/**
 *
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 */
public class AjouterSommetAction extends AbstractAction {

    private Sommet parent;
    private DelegateTreeOperators<Sommet, Arrete> tree;
    private Sommet addedChild;
    private Arrete addedEdge;
    private String nomSommet;
    private String nomArrete;
    private Sommet.Type type = Sommet.Type.ABSTRACTION;

    public AjouterSommetAction(DelegateTreeOperators<Sommet, Arrete> tree, Sommet parent, String nomSommet, String nomArrete) {
        this.parent = parent;
        this.tree = tree;
        this.nomSommet = nomSommet;
        this.nomArrete = nomArrete;
    }

    /**
     * Avec type spécifié
     *
     */
    public AjouterSommetAction(DelegateTreeOperators<Sommet, Arrete> tree, Sommet parent, String nomSommet, String nomArrete, Type typ) {
        this.parent = parent;
        this.tree = tree;
        this.nomSommet = nomSommet;
        this.nomArrete = nomArrete;
        this.type = typ;
    }

    @Override
    protected void doInitialize() {
        addedChild = new Sommet(nomSommet, type);
        addedEdge = new Arrete(nomArrete);
    }

    @Override
    public void doExecute() {
        tree.addChild(addedEdge, parent, addedChild);
    }

    @Override
    public void doReverse() {
        tree.removeChild(addedChild);
    }

    @Override
    public boolean canReverse() {
        return true;
    }

    @Override
    public boolean canExecute() {
        return true;
    }

    @Override
    public String getNom() {
        return "Ajout sommet";
    }
}
